package com.murfrosoft.airhockey.services;

import java.util.List;

import com.murfrosoft.airhockey.entities.*;

import android.graphics.PointF;



public class CollisionDetectorServiceImpl implements CollisionDetectorService{

	@Override
	public void checkForCollision(Puck puck, Paddle paddle) {
		float r_sum = puck.getRadius() + paddle.getRadius();
		float a = (paddle.getOldPositionX() - puck.getPositionX())*(paddle.getPositionX() - puck.getPositionX());
		float b = (paddle.getPositionY() - puck.getPositionY())*(paddle.getPositionY() - puck.getPositionY());
		if( Math.sqrt(a+b) <= r_sum ){
			float coll_pt_x = (paddle.getPositionX() + puck.getPositionX())/2;
			float coll_pt_y = (paddle.getPositionY() + puck.getPositionY())/2;
			// calculate new puck velocity:
			// if collision is from below:
			if( coll_pt_x < puck.getPositionX() ){
				puck.setVelocityX(Math.abs(puck.getVelocityX()) + paddle.getVelocityX());
			}
			else{
				puck.setVelocityX( (-1)*Math.abs(puck.getVelocityX()) - paddle.getVelocityX());  // have no idea if this really works
			}
			if( coll_pt_y < puck.getVelocityY() ){
				puck.setVelocityY( Math.abs(puck.getVelocityY()) + paddle.getVelocityY());
			}
			else{
				puck.setVelocityY( (-1)*Math.abs(puck.getVelocityY()) - paddle.getVelocityY());  // have no idea if this really works
			}
		}
		
	}






	
	
}
